package com.hankol.community.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.baselibrary.bean.VideoReadBean;
import com.hankol.community.fragment.VideoDetailsFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 关忆北、
 * @description 新版视频详情
 * @time 2022/4/10 1:44 下午
 */
public class VideoDetailsAdapter extends FragmentStateAdapter {
    private int browseNum;
    private long toppingCommentId;
    private boolean isOpenComment;
    private List<VideoReadBean.DataBeanX.DataBean> beanList;
    private ArrayList<VideoDetailsFragment> fragments = new ArrayList<>();

    public ArrayList<VideoDetailsFragment> getFragments() {
        return fragments;
    }

    public VideoDetailsAdapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
        beanList = new ArrayList<>();
    }

    public void setDataList(int browseNum, boolean isOpenComment, long toppingCommentId, List<VideoReadBean.DataBeanX.DataBean> beanList) {
        this.beanList = beanList;
        this.browseNum = browseNum;
        this.isOpenComment = isOpenComment;
        this.toppingCommentId = toppingCommentId;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        VideoDetailsFragment videoDetailsFragment = VideoDetailsFragment.Companion.newInstance(beanList.get(position).getId(), position, browseNum, position == 0 && isOpenComment, toppingCommentId);
        //position == 0 第一个视频 如果是第一个视频 isOpenComment=true 则打开评论
        fragments.add(videoDetailsFragment);
        return videoDetailsFragment;
    }

    @Override
    public int getItemCount() {
        return beanList.size();
    }
}